package www.openteam.com.model.qualityCntrl;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.FQCBadItem;
import www.openteam.com.bean.FQCCheckItem;
import www.openteam.com.bean.FQCCheckMan;
import www.openteam.com.bean.FQCCrMaMi;
import www.openteam.com.bean.FQCGoodsField;
import www.openteam.com.bean.FQCGoodsInspect;
import www.openteam.com.bean.FQCHalfGoodsInspect;
import www.openteam.com.bean.FQCSamplePlan;

/**
 * Created by Administrator on 2018/3/23 0023.
 */

public class FQCModel extends BaseModel{


    public void findSamplePlan( int checkNum,final SamplePlanListener listener){
        httpApiService.findFQCSamplePlan(checkNum).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FQCSamplePlan>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(FQCSamplePlan fqcSamplePlan) {
                        listener.success(fqcSamplePlan);
                    }
                })
        ;
    }

    public void findSamplePlanResult( int checkNum,String code,final SamplePlanResultListener listener){
        httpApiService.findFQCSamplePlanResult(code,checkNum).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FQCSamplePlan>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(FQCSamplePlan fqcSamplePlan) {
                        listener.success(fqcSamplePlan);
                    }
                })
        ;
    }

    public void findElement( int checkNum,int element,final ElementListener listener){
        httpApiService.findCR(checkNum,element).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FQCCrMaMi>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(FQCCrMaMi fqcCrMaMi) {
                        listener.success(fqcCrMaMi);
                    }
                })
        ;
    }

    public void findCheckItem( final CheckItemListener listener){
        httpApiService.findFQCCheckItem().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FQCCheckItem>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(FQCCheckItem fqcCheckItem) {
                        listener.success(fqcCheckItem);
                    }
                })
        ;
    }

    public void findBadItem( String code,final BadItemListener listener){
        httpApiService.findFQCBadItem(code).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FQCBadItem>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(FQCBadItem fqcBadItem) {
                        listener.success(fqcBadItem);
                    }
                })
        ;
    }

    public void findGoodsYeild( final GoodsYeildListener listener){
        httpApiService.findGoodsYield().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FQCGoodsField>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(FQCGoodsField data) {
                        listener.success(data);
                    }
                })
        ;
    }

    public void findFQCGoodsInspect( final GoodsInspectListener listener){
        httpApiService.findFQCGoodsInspect().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FQCGoodsInspect>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(FQCGoodsInspect data) {
                        listener.success(data);
                    }
                })
        ;
    }

    public void findFQCHalfGoodsInspect( final HalfGoodsInspectListener listener){
        httpApiService.findFQCHalfGoodsInspect().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FQCHalfGoodsInspect>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(FQCHalfGoodsInspect data) {
                        listener.success(data);
                    }
                })
        ;
    }

    public void findFQCCheckMan( final CheckManListener listener){
        httpApiService.findFQCCheckMan().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<FQCCheckMan>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(FQCCheckMan data) {
                        listener.success(data);
                    }
                })
        ;
    }

    public interface SamplePlanListener{
        void success(FQCSamplePlan fqcSamplePlan);

        void fail(Throwable e);
    }

    public interface SamplePlanResultListener{
        void success(FQCSamplePlan fqcSamplePlan);

        void fail(Throwable e);
    }

    public interface ElementListener{
        void success(FQCCrMaMi fqcCrMaMi);

        void fail(Throwable e);
    }

    public interface CheckItemListener{
        void success(FQCCheckItem fqcCheckItem);

        void fail(Throwable e);
    }

    public interface BadItemListener{
        void success(FQCBadItem fqcBadItem);

        void fail(Throwable e);
    }

    public interface GoodsYeildListener{
        void success(FQCGoodsField data);

        void fail(Throwable e);
    }

    public interface GoodsInspectListener{
        void success(FQCGoodsInspect data);

        void fail(Throwable e);
    }

    public interface HalfGoodsInspectListener{
        void success(FQCHalfGoodsInspect data);

        void fail(Throwable e);
    }

    public interface CheckManListener{
        void success(FQCCheckMan data);

        void fail(Throwable e);
    }
}
